//////////////////////////////////////////////////////////
 // D720201 and D720202 FW Download Solution for Linux //
//////////////////////////////////////////////////////////

RENESAS provides a FW Download Solution for D720201 and D720202.
Because of continual updates to the xHCI driver in successive Linux kernel versions, 
applying the FW Download solution to different Linux kernel versions requires some 
differences in the details of the procedure.  This Note describes the method of applying
the FW Download solution.

Refer to the below contents for your Linux kernel version.

------------------------------------------------------------------------------------------
Table of Contents
------------------------------------------------------------------------------------------
1. How to apply FW Download function to Linux OS with kernel 2.6.xx.xx.
2. How to apply FW Download function to Linux OS with kernel 3.0.xx 
3. How to apply FW Download function to Linux OS with kernel 3.2.xx or later
4. How to apply a patch file
5. Confirmed kernel version 

------------------------------------------------------------------------------------------
1. How to apply FW Download function to Linux OS with kernel 2.6.xx.xx.
------------------------------------------------------------------------------------------

1) Copy "renesas" directory including firmware file to "/lib/firmware".
   Note: Please check if the firmware version is the latest or not.
         When you change the firmware file from K2026090.mem to the latest 
         version, you need to change "renesas/K2026090.mem" in the 
         xhci-fwdload.c to the new firmware file name (Eg. Kxxxxxxx.mem).
         #define XHCI_FWFILENAME_720201_202ES20  "renesas/Kxxxxxxx.mem"

2) Copy xhci-fwdload.h and xhci-fwdload.c to: 
    "/usr/src/kernels/linux/drivers/usb/host".

3) Modify the following four files. You need to modify source code as below: 

   (1) "/usr/src/kernels/linux/drivers/usb/host/Makefile"
     
     (1-1) Add "xhci-fwdload.o" at the end of line starting with "xhci-hcd-objs: =".

      Refer to merged_files/2.6.X.X/Makefile.
   
   (2) "/usr/src/kernels/linux/drivers/usb/host/xhci.h"

     (2-1) Add "#include "xhic-fwdload.h" " at the beginning of the xhci.h file.
     
     (2-2) Add variable member "struct firmware * firmware_pointer" 
           in the "struct xhci_hcd".

      Refer to merged_files/2.6.X.X/xhci.h.

   (3) "/usr/src/kernels/linux/drivers/usb/host/xhci-pci.c"

     (3-1) Add "XHCI_FWDOWNLOAD(hcd);" to beginning of xhci_pci_setup() function

     (3-2) If xhci_pci_resume() function exists,
           add "XHCI_FWRELOAD(hcd);" at the beginning of the function.
         
     (3-3) If xhci_pci_remove() function exists,
           add "XHCI_FWUNLOAD(pci_get_drvdata(dev));" at the beginning of the function.
      
     (3-4) If xhci_pci_remove() function does not exists,
           add "XHCI_FWUNLOAD (hcd) at the next line of "XHCI_FWDOWNLOAD (hcd) in the 
           xhci_pci_setup() function. 

      Refer to merged_files/2.6.x.x/xhci-pci.c

   (4) "/usr/src/kernels/linux/drivers/usb/host/xhci.c"

     (4-1) If xhci_pci_resume function exits,
           modify the following codes at the if(!hibernated){} block.

           before)
			if (handshake(xhci, &xhci->op_regs->status,
			      STS_RESTORE, 0, 10*100)) {
           after)
			if (handshake(xhci, &xhci->op_regs->status,
			      STS_RESTORE, 0, 50*100)) {


4) Compile kernel and install
   # make
   # make modules_install
   # make install


------------------------------------------------------------------------------------------
2. How to apply FW Download function to Linux OS with kernel 3.0.xx
------------------------------------------------------------------------------------------

1) Copy "renesas" directory including firmware file to "/lib/firmware".
   Note: Please check if the firmware version is latest or not.
         When you change the firmware file from K2026090.mem to the latest 
         version, you need to change "renesas/K2026090.mem" in the 
         xhci-fwdload.c to new firmware file name(Eg. Kxxxxxxx.mem).
         #define XHCI_FWFILENAME_720201_202ES20  "renesas/Kxxxxxxx.mem"

2) Copy xhci-fwdload.h and xhci-fwdload.c to: 
    "/usr/src/kernels/linux/drivers/usb/host".

3) Modify the following three files. You need to modify source code as below. 
   You can apply a patch file for this modification. Regarding how to apply the patch 
   file, please see "4. How to apply a patch file".

   (1) "/usr/src/kernels/linux/drivers/usb/host/Makefile"
     
     (1-1) Add "xhci-fwdload.o" at the end of line starting with "xhci-hcd-objs: =".

     Refer to 1st Line of "patch/patch-FWDownload-3_0_101.patch".
   
   (2) "/usr/src/kernels/linux/drivers/usb/host/xhci-pci.c"

     (2-1) Add "XHCI_FWDOWNLOAD(hcd);" to xhci_pci_setup() function.

     (2-2) Add "XHCI_FWUNLOAD(pci_get_drvdata(dev));" to xhci_pci_remove() function.

     (2-3) Add "XHCI_FWRELOAD(hcd);" to xhci_pci_resume() function.
     
     Refer to 13th Line of "patch/patch-FWDownload-3_0_101.patch".

   (3) "/usr/src/kernels/linux/drivers/usb/host/xhci.h"

     (3-1) Add "#include "xhic-fwdload.h" " at the beginning of the xhci.h file.
     
     (3-2) Add variable member "struct firmware * firmware_pointer" 
           in the "struct xhci_hcd".
     
     Refer to 44th Line of "patch/patch-FWDownload-3_0_101.patch".


4) Compile kernel and install
   # make
   # make modules_install
   # make install


------------------------------------------------------------------------------------------
3. How to apply FW Download function to Linux OS with kernel 3.2.xx or later
------------------------------------------------------------------------------------------

1) Copy "renesas" directory including firmware file to "/lib/firmware".
   Note: Please check if the firmware version is latest or not.
         When you change the firmware file from K2026090.mem to the latest 
         version, you need to change "renesas/K2026090.mem" in the 
         xhci-fwdload.c to new firmware file name (Eg. Kxxxxxxx.mem).
         #define XHCI_FWFILENAME_720201_202ES20  "renesas/Kxxxxxxx.mem"

2) Copy xhci-fwdload.h and xhci-fwdload.c to: 
    "/usr/src/kernels/linux/drivers/usb/host".

3) Modify the following three files. You need to modify source codes as below. 
   You can apply a patch file for this modification. Regarding how to apply the patch 
   file, please see "4. How to apply a patch file".

   (1) "/usr/src/kernels/linux/drivers/usb/host/Makefile"
     
     (1-1) Add "xhci-fwdload.o" at the end of line starting with "xhci-hcd-objs: =".

     Refer to 1st Line of "patch/patch-FWDownload-3_2_47.patch".

   (2) "/usr/src/kernels/linux/drivers/usb/host/xhci-pci.c"
   
     (2-1) Add "XHCI_FWUNLOAD(pci_get_drvdata(dev));" to xhci_pci_remove() function.
     
     (2-2) Add "XHCI_FWRELOAD(hcd);" to xhci_pci_resume() function.
         
     Refer to 13th Line of "patch/patch-FWDownload-3_2_47.patch".

   (3) "/usr/src/kernels/linux/drivers/usb/host/xhci.c"

     (3-1) Add "XHCI_FWDOWNLOAD(hcd);" to xhci_gen_setup() function.

     Refer to 34th Line of "patch/patch-FWDownload-3_2_47.patch".

   
   (4) "/usr/src/kernels/linux/drivers/usb/host/xhci.h"

     (4-1) Add "#include "xhic-fwdload.h" " at the beginning of the xhci.h file.
     
     (4-2) Add variable member "struct firmware * firmware_pointer" 
           in the "struct xhci_hcd".
     
     Refer to 46th Line of "patch/patch-FWDownload-3_2_47.patch".


4) Compile kernel and install
   # make
   # make modules_install
   # make install

------------------------------------------------------------------------------------------
4. How to apply a patch file
------------------------------------------------------------------------------------------

To apply a patch file, you can use the "patch" command as below after changing the 
dirctory to "/usr/src/kernels/linux-x.x.x/drivers/usb/host".

 # patch < /path/to/file/
 
Regarding "patch" command, please confirm help message.
 
 $ patch --help
 

------------------------------------------------------------------------------------------
5. Confirmed kernel version
------------------------------------------------------------------------------------------

The following versions have been confirmed for FW Download Solution usability:

  <kernel version>
 2.6.32.59, 2.6.35.4, 2.6.39.4
 3.0.61, 3.0.83, 3.0.101(EOL)
 3.2.37, 3.2.47, 3.2.53
 3.4.50, 3.4.75
 3.7.10(EOL)
 3.8.13(EOL)
 3.9.7, 3.9.11(EOL)
 3.10.25
 3.11.10(EOL)

